package com.cjkj.user.service.impl;

import com.cjkj.common.utils.DateUtils;
import com.cjkj.common.utils.uuid.IdUtils;
import com.cjkj.user.domain.UserInfo;
import com.cjkj.user.mapper.UserInfoMapper;
import com.cjkj.user.service.IUserInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户信息Service业务层处理
 * 
 * @author cjkj
 * @date 2024-08-16
 */
@Service
public class UserInfoServiceImpl implements IUserInfoService {

    @Resource
    private UserInfoMapper userInfoMapper;

    @Override
    public boolean phoneHasRegistered(String phone) {
        UserInfo userInfo = userInfoMapper.selectByPhone(phone);
        return userInfo != null;
    }

    /**
     * 新增用户信息
     *
     * @param userInfo 用户信息
     * @return 结果
     */
    @Override
    public int insertUserInfo(UserInfo userInfo) {
        userInfo.setId(IdUtils.fastSimpleUUID());
        userInfo.setCreateTime(DateUtils.getNowDate());
        userInfo.setStatus(0);
        return userInfoMapper.insertUserInfo(userInfo);
    }

    @Override
    public UserInfo hasLogin(String phone, String password) {
        return userInfoMapper.selectByPhoneAndPwd(phone, password);
    }

    @Override
    public UserInfo getUserByPhone(String phone) {
        return userInfoMapper.selectByPhone(phone);
    }

    /**
     * 修改用户信息
     * 
     * @param userInfo 用户信息
     * @return 结果
     */
    @Override
    public int updateUserInfo(UserInfo userInfo)
    {
        return userInfoMapper.updateUserInfo(userInfo);
    }
}
